package com.developer.platform.application.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.developer.platform.application.query.assembler.TemplateAssembler;
import com.developer.platform.application.query.dto.ResponseModel;
import com.developer.platform.application.query.dto.TemplateDto;
import com.developer.platform.domain.Template;
import com.developer.platform.infrastructure.data.mapper.TemplateMapper;
import com.veeker.core.bean.Pageable;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-12-29
 */
@Component
public class TemplateQueryManager {

  private final TemplateMapper templateMapper;
  private final TemplateAssembler templateAssembler;

  public TemplateQueryManager(
      TemplateMapper templateMapper,
      TemplateAssembler templateAssembler) {
    this.templateMapper = templateMapper;
    this.templateAssembler = templateAssembler;
  }

  public ResponseModel<TemplateDto> page(Pageable pageable){
    LambdaQueryWrapper<Template> queryWrapper = new LambdaQueryWrapper<>();
    return templateAssembler.toTemplateDtoPage(
        templateMapper.selectPage(new Page<>(pageable.getPageNumber(),
            pageable.getPageSize()),queryWrapper));
  }

}
